package com.demostic.demostic_test.utils;

import android.text.InputFilter;
import android.text.Spanned;
import android.widget.EditText;

import java.util.regex.Pattern;

public class UserUtils {
    public static boolean isEmail(String email) {
        return Pattern.compile("^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$").matcher(email).matches();
    }

    public static boolean checkPhysicalId(String id) {
        return Pattern.compile("^[A-Z0-9a-z]{12}$").matcher(id).matches();
    }

    public static boolean rexCheckPassword(String ssid) {
        return Pattern.compile("[a-z0-9A-Z`~!@#$%^&*()+=_|\\-{\\\\}'\":;,\\[\\].<>/?¥…\\s*]+").matcher(ssid).matches();
    }

    public static boolean checkPassword(String pw) {
        return Pattern.compile("^[A-Z0-9a-z]{6,12}$").matcher(pw).matches();
    }

    public static boolean isNameMatch(String name) {
        return Pattern.compile("[\\u4E00-\\u9FA5a-z0-9A-Z`~!@#$%^&*()+=-|{\\\\}':;,[\\\\].<>/?¥…《》、；：‘’？“”【】·！￥（）\\-—— ]+").matcher(name).matches();
    }

    public static void setInputFilter(EditText editText) {
        editText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(12), new InputFilter() {
            /* class com.demostic.demostic_test.utils.UserUtils.AnonymousClass1 */

            @Override // android.text.InputFilter
            public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
                if (!UserUtils.isMatch(source.toString())) {
                    return "";
                }
                return null;
            }
        }});
    }

    public static boolean isMatch(String str) {
        return Pattern.compile("[\\u4E00-\\u9FA5a-z0-9A-Z`~!@#$%^&*()+=-|{\\\\}':;,[\\\\].<>/?¥…]+").matcher(str).matches();
    }

    public static String exChange(String address) {
        String str = address.replaceAll("[:]", "");
        StringBuffer sb = new StringBuffer();
        if (str != null) {
            for (int i = 0; i < str.length(); i++) {
                char c = str.charAt(i);
                if (Character.isLowerCase(c)) {
                    sb.append(Character.toUpperCase(c));
                } else {
                    sb.append(c);
                }
            }
        }
        return sb.toString();
    }

    public static String exChanges(String address) {
        String str = address.replaceAll("[:]", "");
        StringBuffer sb = new StringBuffer();
        if (str != null) {
            for (int i = 0; i < str.length(); i++) {
                char ch = str.charAt(i);
                if (i == str.length() - 1) {
                    String c = Integer.toHexString(Integer.parseInt(ch + "", 16) - 1);
                    if (Character.isLowerCase(c.charAt(0))) {
                        sb.append(c.toUpperCase());
                    } else {
                        sb.append(c);
                    }
                } else if (Character.isLowerCase(ch)) {
                    sb.append(Character.toUpperCase(ch));
                } else {
                    sb.append(ch);
                }
            }
        }
        return sb.toString();
    }
}
